﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;
using System.Globalization;
using System.Resources;

using EHTWebsite.Code;

namespace EHTWebsiteProject
{
    public partial class KhachHangDetail : System.Web.UI.Page
    {
        public Int32 KhachHangID = HangSo.DEFAULT_ID;
        public String HrefUrl = "";

        private Boolean IsVN = true;
        private String languageCode = "vi-VN";
        private ResourceManager rm = new ResourceManager("Resources.SiteMap", System.Reflection.Assembly.Load("App_GlobalResources"));

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                languageCode = Session[HangSo.LANGUAGE_CODE].ToString();

                if (languageCode == "en-us")
                {
                    IsVN = false;
                }

            }
            catch (Exception ex)
            {
            }

            try
            {
                KhachHangID = Int32.Parse(Request.QueryString["KhachHangID"].ToString());
            }
            catch (Exception)
            {
                KhachHangID = HangSo.DEFAULT_ID;
            }


            KhachHang theKhachHang = KhachHangProvider.GetKhachHangByKhachHangID(KhachHangID);

            if (theKhachHang == null)
                Response.Redirect("~/trang-chu.aspx");
            else
            {
                this.ltrDienThoai.Text = theKhachHang.DienThoai;
                this.ltrEmail.Text = theKhachHang.Email;
                this.imgHinhAnh.ImageUrl = "~/ImageDatas/Customers/" + theKhachHang.HinhAnhUrl;
                this.ltrWebsite.Text = "<a href='" + theKhachHang.Website + "' target='_blank'>" + theKhachHang.Website + "</a>";
                HrefUrl = theKhachHang.Website;

                if (IsVN == true)
                {
                    this.ltrDiaChi.Text = theKhachHang.DiaChiVN;
                    this.ltrTenKhachHang.Text = theKhachHang.TenKhachHangVN;
                }
                else
                {
                    this.ltrDiaChi.Text = theKhachHang.DiaChiOther;
                    this.ltrTenKhachHang.Text = theKhachHang.TenKhachHangOther;
                }
            }

            Thread.CurrentThread.CurrentCulture = new CultureInfo(languageCode);
            LoadLanguage(Thread.CurrentThread.CurrentCulture);
        }

        public void LoadLanguage(CultureInfo ci)
        {
            this.ltrKhachHang_Title.Text = rm.GetString("ltrKhacHang_Title", ci);
        }
    }
}